package com.bainuo.doctor.common.widget.viewloader;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bainuo.doctor.common.R;
import com.bainuo.doctor.common.util.ImageLoader;
import com.bainuo.doctor.common.util.ViewUtil;
import com.facebook.drawee.view.SimpleDraweeView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by bainuo on 2017/2/8.
 */

public class MyItemView extends FrameLayout {


    public ImageView mImgLeft;
    public TextView mTvLeft;
    public TextView mTvDesc;
    public TextView mTvRight;
    public ImageView mImgRight;
    public LinearLayout mLyMain;
    public SimpleDraweeView mImgSecright;
    public BNCountView mTvCount;
    public View mLine;

    public MyItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public MyItemView(Context context) {
        super(context);
        init(context);
    }

    private void init(Context context) {
        LayoutInflater.from(context).inflate(R.layout.item_my_common, this, true);
//        ButterKnife.bind(this);
        mImgLeft = (ImageView)findViewById(R.id.myitem_img_left);
        mTvLeft = (TextView)findViewById(R.id.myitem_tv_left);
        mTvDesc = (TextView)findViewById(R.id.myitem_tv_desc);
        mTvRight = (TextView)findViewById(R.id.myitem_tv_right);
        mImgRight = (ImageView)findViewById(R.id.myitem_img_right);
        mLyMain = (LinearLayout)findViewById(R.id.myitem_ly_main);
//        mImgSecright = (SimpleDraweeView)findViewById(R.id.myinfo_img_sec_right);
        mTvCount = (BNCountView)findViewById(R.id.contact_head_tv_Count);
        mLine = findViewById(R.id.myitem_iv_line);
    }

    public void setLeftImage(int id) {
        mImgLeft.setVisibility(View.VISIBLE);
        mImgLeft.setImageResource(id);
    }

    public void setRightImage(int id) {
        if(id != 0){
            mImgRight.setVisibility(View.VISIBLE);
            mImgRight.setImageResource(id);
        }else{
            mImgRight.setVisibility(View.INVISIBLE);
        }
    }

    public void setNext(boolean next){
        if (next)
            setRightImage(R.mipmap.ico_my_right);
        else
            mImgRight.setVisibility(GONE);
    }

    public void setLeftText(String str) {
        mTvLeft.setVisibility(View.VISIBLE);
        mTvLeft.setText(str);
    }

    public void setDescViewVisible(boolean visible){
        mTvDesc.setVisibility(visible ? View.VISIBLE : View.GONE);
    }

    public void setDescText(boolean isApplying){
//        mTvDesc.setText(isApplying ? R.string.my_applaying : R.string.my_applay);
    }

    public void setRightText(String str) {
        mTvRight.setVisibility(View.VISIBLE);
        mTvRight.setText(str);
    }

    public void setRightViewTextColor(int colorRes){
        mTvRight.setVisibility(View.VISIBLE);
        mTvRight.setTextColor(getContext().getResources().getColor(colorRes));
    }

    public void setCountText(String count){
       mTvCount.setText(count);
       mTvCount.setVisibility(View.VISIBLE);
    }

    public void showLine(boolean state){
        mLine.setVisibility(state?VISIBLE:GONE);
    }

    public void setSmallRedPoint(){
        ViewUtil.setViewSizeWithDp(mTvCount,10,10);
    }
    public void setRightSecImg(String path) {
        if (path == null)
            return;

        mImgSecright.setVisibility(VISIBLE);
        if (path.contains("http")) {
            ImageLoader.setImage(path, mImgSecright);
        } else {
            ImageLoader.setImage("file://" + path, mImgSecright);
        }
    }
}
